package com.bocai.freeman.view.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseActivity;
import com.bocai.freeman.utils.DividerItemDecoration;
import com.bocai.freeman.utils.ToolbarHelper;
import com.bocai.freeman.view.adapter.PerfectLightAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by win7 on 2016/5/26.
 */
public class PerfectLightActivity extends BaseActivity {
    @Bind(R.id.rv)
    RecyclerView rv;
    @Bind(R.id.swipe_refresh_layout)
    SwipeRefreshLayout swipeRefreshLayout;
    private PerfectLightAdapter mPerfectLightAdapter;
    private List<List<Integer>> mData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_contact);
        ButterKnife.bind(this);
        initView();
        initEvent();
    }

    @Override
    protected void initEvent() {
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefreshLayout.setRefreshing(false);
                    }
                }, 350);
            }
        });
    }


    @Override
    protected void initView() {
        initToobar();
        mData = new ArrayList<>();
        for (int i = 0; i < 9; i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < 9 - i; j++) {
                list.add(R.mipmap.img01);
            }
            mData.add(list);
        }
        Log.e("tag", mData.size() + "");
        mPerfectLightAdapter = new PerfectLightAdapter(this, mData);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL_LIST));
        rv.setAdapter(mPerfectLightAdapter);
        mPerfectLightAdapter.setOnItemClickLitener(new PerfectLightAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(PerfectLightActivity.this,PerfectLightDetailActivity.class));
            }
        });
    }

    private void initToobar() {
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        if (!TextUtils.isEmpty(title))
            ToolbarHelper.setup(this, title, R.mipmap.left_return, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
    }
}
